package com.platform.api.bzproject.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.platform.api.bzproject.model.BzClassification;
import com.platform.api.bzproject.model.BzConfig;
import com.platform.api.bzproject.model.UserClassify;
import com.platform.api.bzproject.service.*;
import com.platform.api.bzproject.vo.TalentVo;
import com.platform.common.core.Constant;
import com.platform.common.core.Result;
import com.platform.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author guoyunfei on 2021/7/9 14:03
 * @className BzClassificationMapper
 * @description TODO
 * @Version 1.0
 * 源码联系微信：2549789059
 */
@Api(tags = "壁纸分类")
@RestController
@RequestMapping("{appid}/classification")
public class BzClassificationController {

    @Autowired
    private BzClassificationService bzClassificationService;


    @Autowired
    private IUserClassifyService iUserClassifyService;
    @Autowired
    private BzAllWallpaperService bzAllWallpaperService;



    @ApiOperation(value = "壁纸分类列表", notes="壁纸分类列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("list")
    public Result bzClassificationList (@PathVariable String appid){

        BzClassification bzClassification = new BzClassification();
        bzClassification.setEnable(1);
        //多账号时开放
        //bzClassification.setAppid(appid);
        List<BzClassification> bzClassifications = bzClassificationService.selectList(bzClassification);

        return Result.success(bzClassifications);
    }


    @GetMapping("classifiList")
    public Result classifiList (@PathVariable String appid){
        List<BzClassification> list = bzClassificationService.list(
                new QueryWrapper<BzClassification>().eq("enable", 1));
        return Result.success(list);
    }

    /**
     * 用户自定义分类
     * @return
     */
    @GetMapping("userClassifiList")
    public Result userClassifiList (UserClassify userClassify){


        LambdaQueryWrapper<UserClassify> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(UserClassify::getId);
        lambdaQueryWrapper.eq(null != userClassify.getParentId(), UserClassify::getParentId,userClassify.getParentId());
        lambdaQueryWrapper.eq(null != userClassify.getStatus(), UserClassify::getStatus,userClassify.getStatus());
        lambdaQueryWrapper.eq(null != userClassify.getUserId(), UserClassify::getUserId,userClassify.getUserId());

        List<UserClassify> userClassifies = iUserClassifyService.list(lambdaQueryWrapper);

        return Result.success(userClassifies);
    }

    @GetMapping("getUserDataClass/{userId}")
    public Result getUserDataClass (@PathVariable String userId){

        List<Integer> userClassIds = bzAllWallpaperService.getUserClassIds(userId);
        if(userClassIds.size() == 0){
            List<BzClassification> list = bzClassificationService.list(
                    new QueryWrapper<BzClassification>().eq("enable", 1));
            return Result.success(list);
        }
        List<BzClassification> list = bzClassificationService.list(
                new QueryWrapper<BzClassification>().eq("enable", 1).in("id",userClassIds));
        return Result.success(list);
    }

}
